import { createApp } from 'vue'
import App from './App.vue'
import router, { setupRouter } from '@/router'
import i18n from '@/i18n/index'
import baiduMap from 'vue3-baidu-map-gl'
import { setupStore } from '@/store'
import { setupNaive, setupDirectives, setupCustomComponents, initFunction } from '@/plugins'
import { GoAppProvider } from '@/components/GoAppProvider/index'
import { setHtmlTheme } from '@/utils'
import * as Cesium from 'cesium';
import "cesium/Build/Cesium/Widgets/widgets.css"; 
Cesium.Ion.defaultAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI4NjUwMjczNC04YmQ3LTQ5MzUtOTMzYi1jN2QyM2FhY2NiYzgiLCJpZCI6MTQzNjg4LCJpYXQiOjE2ODU2NjcyNTB9.zQeik-kCJGNf9ookuIwNE36MRxW1TQt5VUc7bfnn9c8"; // 自己申请 或者放在全局变量 或者挂载原型上调用
window.Cesium = Cesium

// 引入全局样式
import '@/styles/pages/index.scss'
// 引入动画
import 'animate.css/animate.min.css'
// 引入标尺
import 'vue3-sketch-ruler/lib/style.css'

async function appInit() {
  const goAppProvider = createApp(GoAppProvider)

  const app = createApp(App)

  // 注册全局常用的 naive-ui 组件
  setupNaive(app)

  // 注册全局自定义指令
  setupDirectives(app)

  // 注册全局自定义组件
  setupCustomComponents(app)

  // 挂载状态管理
  setupStore(app)

  // 解决路由守卫，Axios中可使用，Dialog，Message 等全局组件
  goAppProvider.mount('#appProvider', true)

  // 挂载路由
  setupRouter(app)

  // 路由准备就绪后挂载APP实例
  await router.isReady()

  // Store 准备就绪后处理主题色
  setHtmlTheme()

  // 语言注册
  app.use(i18n)
  // @ts-ignore
  // eslint-disable-next-line
  app.use(baiduMap, {
    ak: 'rYQHrpflPVCbHNRv7GPHO9QiA8Vlltsk',
    plugins: ['TrackAnimation']
  })

  // 挂载到页面
  app.mount('#app', true)

  // 挂载到 window
  window['$vue'] = app
}

appInit().then(() => {
  initFunction()
})
